package com.mall.shopping.services;

import com.mall.shopping.IContentService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ContentConverter;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dal.persistence.PanelMapper;
import com.mall.shopping.dto.NavListResponse;
import com.mall.shopping.dto.PanelContentDto;
import com.mall.shopping.utils.ExceptionProcessorUtils;
import org.apache.dubbo.config.annotation.Service;
import org.mapstruct.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

import static com.mall.shopping.constant.GlobalConstants.HEADER_PANEL_ID;

/**
 * @program: last-mall
 * @description:
 * @create: 2021-06-17 21:57
 **/
@Service
public class IContentServiceImpl implements IContentService {
	@Autowired
	PanelContentMapper panelContentMapper;
	@Autowired
	ContentConverter contentConverter;


	@Override
	public NavListResponse queryNavList() {
		NavListResponse navListResponse = new NavListResponse();

		try {
			Example example = new Example(PanelContent.class);
			example.createCriteria().andEqualTo("panelId",HEADER_PANEL_ID);
			List<PanelContent> panelContents = panelContentMapper.selectByExample(example);
			List<PanelContentDto> panelContentDtos = contentConverter.panelContents2Dto(panelContents);
			navListResponse.setPannelContentDtos(panelContentDtos);
			navListResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
			navListResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
			return navListResponse;
		} catch (Exception e) {
//			navListResponse.setCode(ShoppingRetCode.SYSTEM_ERROR.getCode());
//			navListResponse.setMsg(ShoppingRetCode.SYSTEM_ERROR.getMessage());
			e.printStackTrace();
			ExceptionProcessorUtils.wrapperHandlerException(navListResponse,e);
		}

		return navListResponse;
	}
}
